Passed
Push — master ( 101140...f03775 )
by Sara
04:41 queued 02:38
created

App.jsx ➔ App   B

Complexity

Conditions 4

Size

Total Lines 84
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 72
dl 0
loc 84
rs 7.9163
c 0
b 0
f 0
cc 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import { useEffect } from 'react'
2
import {
3
    bSecurePayments,
4
    TransactionParameters,
5
    bSecurePaymentsHandler,
6
} from "bsecure-payments-js"
7
8
function App() {
9
  useEffect(() => {
10
    LOCAL_STORAGE_SERVICE._clearLocalStorage();
11
    responseListener();
12
    try {
13
      setTransactionParameters();
14
    } catch (error) {
15
      console.info("error found in setTransactionParameters", error);
16
    }
17
  }, []);
18
19
  const responseListener = () => {
20
    bSecurePaymentsHandler.initialize();
21
    bSecurePaymentsHandler.onErrorAlert = function (msg) {
22
      alert("onErrorAlert")
23
      console.log("onErrorAlert: ", msg) 
24
      return msg;
25
    }
26
    bSecurePaymentsHandler.onSuccessAlert = function (msg) {
27
      alert("onSuccessAlert")
28
      console.log("onSuccessAlert: ", msg)
29
      return msg;
30
    }
31
    bSecurePaymentsHandler.onValidationErrorAlert = function (msg) {
32
      alert("onValidationErrorAlert")
33
      console.log("onValidationErrorAlert: ", msg)
34
      return msg;
35
    }
36
    bSecurePaymentsHandler.onProcessPaymentSuccess = function (msg) {
37
      alert("onProcessPaymentSuccess")
38
      console.log("onProcessPaymentSuccess: ", msg)
39
      return msg;
40
    }
41
    bSecurePaymentsHandler.onProcessPaymentFailure = function (msg) {
42
      alert("onProcessPaymentFailure")
43
      console.log("onProcessPaymentFailure: ", msg)
44
      return msg;
45
    }
46
  };
47
48
49
50
  const setTransactionParameters = () => {
51
    delete TransactionParameters.__17seh__;
52
53
    TransactionParameters.__00trid__ = "xtend-001";
54
    TransactionParameters.__01curr__ = "PKR";
55
    TransactionParameters.__02trdt__ = "6062262";
56
    TransactionParameters.__03stamt__ = 500;
57
    TransactionParameters.__04damt__ = 50;
58
    TransactionParameters.__05tamt__ = 1000;
59
    TransactionParameters.__06cname__ = "Default User";
60
    TransactionParameters.__07ccc__ = "92";
61
    TransactionParameters.__08cphn__ = "3482127668";
62
    TransactionParameters.__09cemail__ = "[email protected]";
63
    TransactionParameters.__10ccc__ = "Pakistan";
64
    TransactionParameters.__11cstate__ = "Sindh";
65
    TransactionParameters.__12ccity__ = "Karachi";
66
    TransactionParameters.__13carea__ = "Karachi Township";
67
    TransactionParameters.__14cfadd__ = "Plot B 450, Sector 11-A Sector 11 A North Karachi Twp, Karachi, Karachi City, Sindh, Pakistan";
68
    TransactionParameters.__15mid__ = "1421";
69
    TransactionParameters.__16stid__ = "ST-005722384";
70
    TransactionParameters.__18ver__ = "1.1";
71
    TransactionParameters.__20red__ = window.location.href;
72
    TransactionParameters.__21cenv__ = 2;
73
    const salt = process.env.REACT_APP_CLIENT_ID;
74
    let _signature = salt + "&";
75
    Object.keys(TransactionParameters)
76
      .sort()
77
      .forEach(function (v, idx, array) {
78
        let _val = TransactionParameters[v].toString().replace(/\s/g, '');
79
        _signature += _val.concat(idx === array.length - 1 ? "" : "&")
80
      });
81
    let _hash = CryptoJS.HmacSHA256(_signature, salt).toString();
82
    TransactionParameters.__17seh__ = _hash.toUpperCase();
83
84
    try {
85
      bSecurePayments.initialize("bSecurePaymentPluginContainer");
86
    } catch (error) {
87
88
89
      return (
90
        <></>
91
      )
92
    }
93
  }
94
}
95
export default App
96